package com.mm.controller;

import com.mm.constant.BusinessConstant;
import com.mm.constant.ResponseConstant;
import com.mm.exception.ServiceException;
import com.mm.model.sys.JsonResponse;
import com.mm.service.CompanyService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 店铺Controller
 *
 * @date 2018/8/1 11:26
 */
@Controller
@RequestMapping(value = "/company")
public class CompanyController {
	private static Logger logger = LoggerFactory.getLogger(CompanyController.class);
	@Autowired
	private CompanyService companyService;

	@ResponseBody
	@RequestMapping(value = "/save")
	public Object save(HttpServletRequest request) {
		Object obj = request.getAttribute(BusinessConstant.PARAMETER_DATA);
		if (obj == null) {
			return new JsonResponse(ResponseConstant.CODE_FAIL, "数据不能为空");
		}
		String data = (String) obj;
		if (StringUtils.isBlank(data)) {
			return new JsonResponse(ResponseConstant.CODE_FAIL, "数据不能为空");
		}
		try {
			companyService.saveCompany(data);
		} catch (ServiceException e) {
			e.printStackTrace();
			logger.error("CompanyController save： " + e.getMessage());
			return new JsonResponse(ResponseConstant.CODE_FAIL, "保存店铺资料失败");
		}
		return "保存店铺资料成功";
	}

}
